package com.any.develop.controller;

import com.any.develop.common.result.Result;
import com.any.develop.entity.User;
import com.any.develop.service.UserService;
import com.sun.javafx.binding.Logging;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/user")
public class UserController {

    @Autowired
    private UserService userService;


    @GetMapping("/findAll")
    public Result findAll(){
        List<User> userList =userService.list();
        return Result.ok().data("userList",userList);
    }

    @GetMapping("/add")
    public Result add(User user){
        boolean flag = userService.save(user);
        return Result.ok().success(flag);
    }

/*    @GetMapping("/getById/{id}")
    public Result getById(@PathVariable Long id){
        User user = userService.getById(id);
        return Result.ok().;
    }*/

    @GetMapping("/delete/{id}")
    public Result  delete(@PathVariable Long id){
        boolean flag = userService.removeById(id);
        if(flag){
            return Result.ok();
        }else{
            return Result.error();
        }

    }

}
